/* GUI CONVERTED from renplf.p (converter v1.76) Sun Aug 25 20:59:39 2002 */
/* renplf.p   - REPETITIVE   NONPRODUCTIVE LABOR FEEDBACK TRANSACTION        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.10.1.4 $                                                              */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*               */
/* REVISION: 8.5      LAST MODIFIED: 05/12/95   BY: pma *J04T*               */
/* REVISION: 7.3      LAST MODIFIED: 08/02/95   BY: dzs *G0SX*               */
/* REVISION: 8.5      LAST MODIFIED: 12/10/95   BY: sxb *J053*               */
/* REVISION: 7.3      LAST MODIFIED: 02/13/96   BY: rvw *G1N0*               */
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*               */
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: *G1V9* Julie Milligan    */
/* REVISION: 7.3      LAST MODIFIED: 05/28/96   BY: rvw *G1WJ*               */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: ejh *K001*               */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton      */
/* REVISION: 9.1      LAST MODIFIED: 07/21/00   BY: *N0GD* Peggy Ng          */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0ND* Mark Brown        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* $Revision: 1.10.1.4 $    BY: Vivek Gogte           DATE: 08/06/02  ECO: *N1QQ*     */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* (TAKEN FROM reoptr15.p) */

/* DISPLAY TITLE */
{mfdtitle.i "2+ "}

{gldydef.i new}
{gldynrm.i new}

{gpglefv.i}

define new shared variable start_time   as   character.
define new shared variable stop_time    as   character.
define new shared variable error_flag   like mfc_logical.
define new shared variable opgltype     like opgl_type.
define new shared variable time_hm1     as   character format "999:99:99".
define new shared variable time_hm2     as   character format "999:99:99".
define new shared variable time_hd1     as   decimal   format "->>>9.999".
define new shared variable time_hd2     as   decimal   format "->>>9.999".
define new shared variable non_numeric  as   integer.
define new shared variable sf_cr_acct   like dpt_lbr_acct.
define new shared variable sf_dr_acct   like dpt_lbr_acct.
define new shared variable sf_cr_sub    like dpt_lbr_sub.
define new shared variable sf_dr_sub    like dpt_lbr_sub.
define new shared variable sf_cr_cc     like dpt_lbr_cc.
define new shared variable sf_dr_cc     like dpt_lbr_cc.
define new shared variable sf_gl_amt    like tr_gl_amt.
define new shared variable ref          like glt_ref.
define new shared variable op_recno     as   recid.
define new shared variable sf_entity    like en_entity.
define new shared variable time_ind     like mfc_logical label "Time Ind"
   format "Decimal Hours/Hours Minutes".

define variable yn                 like mfc_logical                   no-undo.
define variable elapse             as   decimal format ">>>>>>>>.999" no-undo.
define variable i                  as   integer                       no-undo.
define variable j                  as   integer                       no-undo.
define variable date_change        as   integer                       no-undo.
define variable trnbr              like op_trnbr                      no-undo.
define variable emp                like op_emp                        no-undo.
define variable earn               like op_earn label "Pay Code"      no-undo.
define variable shift              like op_shift                      no-undo.
define variable dept               like op_dept label "Dept"          no-undo.
define variable dptdesc            like dpt_desc                      no-undo.
define variable project            like op_project                    no-undo.
define variable rsn_desc1          like rsn_desc format "x(22)"       no-undo.
define variable pay_rate           like emp_pay_rate                  no-undo.
define variable valid_proj         like mfc_logical                   no-undo.
define variable sf_lbr_acct        like dpt_lbr_acct                  no-undo.
define variable sf_bdn_acct        like dpt_bdn_acct                  no-undo.
define variable sf_cop_acct        like dpt_cop_acct                  no-undo.
define variable sf_lbr_sub         like dpt_lbr_sub                   no-undo.
define variable sf_bdn_sub         like dpt_bdn_sub                   no-undo.
define variable sf_cop_sub         like dpt_cop_sub                   no-undo.
define variable sf_lbr_cc          like dpt_lbr_cc                    no-undo.
define variable sf_bdn_cc          like dpt_bdn_cc                    no-undo.
define variable sf_cop_cc          like dpt_cop_cc                    no-undo.
define variable eff_date           like op_date initial today         no-undo.
define variable site               like si_site                       no-undo.
define variable gledger            as   character format "x(18)"      no-undo.
define variable start_run          as   character format "x(9)"
                                   label  "Start Down"                no-undo.
define variable stop_run           as   character format "x(9)"
                                   label  "Elapsed/Stop Down"         no-undo.

gledger = getTermLabel("GENERAL_LEDGER",18).

{sfnplfrm.i}

/* DISPLAY */
view frame a.

for first ea_mstr
   fields (ea_earn ea_rate ea_type)
   where ea_type = "1"
   no-lock:

   earn = ea_earn.
end. /* FOR FIRST ea_mstr */

if not available ea_mstr
then
   earn = "".

for first opc_ctrl
   fields (opc_time_ind)
   no-lock:
end. /* FOR FIRST opc_ctrl */

if available opc_ctrl
   and opc_time_ind = "D"
then
   time_ind = yes.
else
   time_ind = no.

release opc_ctrl.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.


   do transaction with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      assign
         start_run   = ""
         stop_run    = ""
         rsn_desc1   = ""
         dept        = ""
         dptdesc     = "".

      ststatus    = stline[1].
      status input ststatus.

      display
         earn
         eff_date
         "DOWN" @ op_type
         rsn_desc1
         time_ind
         dept
         dptdesc
         0 @ op_act_run
         start_run
         stop_run.

      display
         global_site @ site.

      set_ophist:
      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         prompt-for
            emp
            shift
            earn
            project
            eff_date
            op_wkctr
            op_mch
            site
            dept
            op_rsn
            time_ind
            start_run
            stop_run
            op_comment
         editing:

            if frame-field = "emp"
            then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp.i emp_mstr emp emp_addr emp emp_addr emp_addr}

               if recno <> ?
               then do:

                  for first dpt_mstr
                     fields (dpt_bdn_acct dpt_bdn_cc dpt_bdn_sub
                             dpt_cop_acct dpt_cop_cc dpt_cop_sub
                             dpt_dept dpt_desc
                             dpt_lbr_acct dpt_lbr_cc dpt_lbr_sub)
                     where dpt_dept = emp_dept
                     no-lock:

                     dptdesc = dpt_desc.
                  end. /* FOR FIRST dpt_mstr */

                  if not available dpt_mstr
                  then
                     dptdesc = "".

                  display
                     emp_addr @ emp
                     emp_lname
                     emp_dept @ dept
                     dptdesc
                     emp_project @ project.

               end. /* IF recno <> ? */
            end. /* IF frame-field = "emp" */

            else if frame-field = "op_wkctr"
            then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp.i
                  wc_mstr op_wkctr wc_wkctr op_mch wc_mch wc_wkctr}

               if recno <> ?
               then do:

                  display
                     wc_wkctr @ op_wkctr
                     wc_mch @ op_mch.

                  if input emp = ""
                  then do:

                     for first dpt_mstr
                        fields (dpt_bdn_acct dpt_bdn_cc dpt_bdn_sub
                                dpt_cop_acct dpt_cop_cc dpt_cop_sub
                                dpt_dept dpt_desc
                                dpt_lbr_acct dpt_lbr_cc dpt_lbr_sub)
                        where dpt_dept = wc_dept
                        no-lock:

                        dptdesc = dpt_desc.
                     end. /* FOR FIRST dpt_mstr */

                     if not available dpt_mstr
                     then
                        dptdesc = "".

                     display
                        wc_dept @ dept
                        dptdesc.

                  end. /* IF INPUT emp = "" */
               end. /* IF recno <> ? */
            end. /* ELSE IF frame-field = "op_wkctr" */

            else if frame-field = "op_mch"
            then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp01.i
                  wc_mstr op_mch wc_mch
                  "input op_wkctr" wc_wkctr wc_wkctr}

               if recno <> ?
               then do:

                  display
                     wc_wkctr @ op_wkctr
                     wc_mch @ op_mch.

                  if input emp = ""
                  then do:

                     for first dpt_mstr
                        fields (dpt_bdn_acct dpt_bdn_cc dpt_bdn_sub
                                dpt_cop_acct dpt_cop_cc dpt_cop_sub
                                dpt_dept dpt_desc
                                dpt_lbr_acct dpt_lbr_cc dpt_lbr_sub)
                        where dpt_dept = wc_dept
                        no-lock:

                        dptdesc = dpt_desc.
                     end. /* FOR FIRST dpt_mstr */

                     if not available dpt_mstr
                     then
                        dptdesc = "".

                     display
                        wc_dept @ dept
                        dptdesc.

                  end. /* IF INPUT emp = "" */
               end. /* IF recno <> ? */
            end. /* ELSE IF frame-field = "op_mch" */

            else if frame-field = "op_rsn"
            then do:

               /* FIND NEXT/PREVIOUS RECORD */
               {mfnp01.i rsn_ref op_rsn rsn_code "input op_type"
                  rsn_type rsn_type}

               if recno <> ?
               then
                  display
                     rsn_code @ op_rsn
                     rsn_desc @ rsn_desc1.
            end. /* ELSE IF frame-field = "op_rsn" */

            else do:
               status input.
               readkey.
               apply lastkey.
            end. /* ELSE DO OF IF frame-field= "op_rsn", frame-field= op_mch */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* PROMPT-FOR ... */

         for first si_mstr
            fields (si_entity si_site)
            where si_site = input site
            no-lock:
         end. /* FOR FIRST si_mstr */

         if not available si_mstr
         then do:

            /* SITE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
            next-prompt
               site.
            undo, retry.
         end. /* IF NOT AVAILABLE si_mstr */

         {gprun.i ""gpsiver.p""
            "(input site,
              input recid(si_mstr),
              output return_int)"
         }
/*GUI*/ if global-beam-me-up then undo, leave.


         if return_int = 0
         then do:

            /*USER DOES NOT HAVE ACCESS TO THIS SITE */
            {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
            next-prompt site.
            undo, retry.
         end. /* IF return_int = 0 */

         sf_entity = si_entity.

         /* VALIDATE PROJECT */
         assign
            project.

         {gprunp.i "gpglvpl" "p" "initialize"}

         {gprunp.i "gpglvpl" "p" "validate_project"
            "(input  project,
              output valid_proj)"}

         if not valid_proj
         then do:
            next-prompt
               project.
            undo, retry.
         end. /* IF NOT valid_proj */

         assign
            eff_date.

         if eff_date = ?
         then
            eff_date = today.

         /* CHECK GL EFFECTIVE DATE */
         {gpglef1.i   &module = ""IC""
            &entity = si_entity
            &date = eff_date
            &prompt = "eff_date"
            &frame = "a"
            &loop = "set_ophist"
            }

         if input emp <> ""
         then do:

            for first emp_mstr
               fields (emp_addr emp_dept emp_lname emp_pay_rate emp_pay_type
                       emp_project emp_status)
               where emp_addr = input emp
               no-lock:
            end. /* FOR FIRST emp_mstr */

            if not available emp_mstr
            then do:

               /* EMPLOYEE NUMBER DOES NOT EXIST. */
               {pxmsg.i &MSGNUM=520 &ERRORLEVEL=3}
               next-prompt
                  emp.
               undo, retry.
            end. /* IF NOT AVAILABLE emp_mstr */

            if lookup(emp_status,"AC,PT") = 0
            then do:

               next-prompt emp.
               /* "EMPLOYEE NOT ON ACTIVE STATUS" */
               {pxmsg.i &MSGNUM=4027 &ERRORLEVEL=3}
               undo,retry.
            end. /* IF lookup(emp_status,"AC,PT") = 0  */

            if input project = ""
            then do:
               project = emp_project.
               display
                  project.
            end. /* IF INPUT project = "" */

            if input earn <> ""
            then do:

               for first ea_mstr
                  fields (ea_earn ea_rate ea_type)
                  where ea_earn = input earn
                  no-lock:
               end. /* FOR FIRST ea_mstr */

               if not available ea_mstr
               then do:

                  /* INVALID EARNINGS CODE */
                  {pxmsg.i &MSGNUM=4025 &ERRORLEVEL=3}
                  next-prompt
                     earn.
                  undo, retry.
               end. /* IF NOT AVAILABLE ea_mstr */

            end. /* IF INPUT earn <> "" */

            assign
               dept.

            if available emp_mstr
               and input dept = ""
            then do:

               dept = emp_dept.
               display
                  dept.
            end. /* IF AVAILABLE emp_mstr ... */

            for first dpt_mstr
               fields (dpt_bdn_acct dpt_bdn_cc dpt_bdn_sub
                       dpt_cop_acct dpt_cop_cc dpt_cop_sub
                       dpt_dept dpt_desc
                       dpt_lbr_acct dpt_lbr_cc dpt_lbr_sub)
               where dpt_dept = dept
               no-lock:
            end. /* FOR FIRST dpt_mstr */

            if not available dpt_mstr
            then do:

               /* DEPARTMENT NOT FOUND */
               {pxmsg.i &MSGNUM=532 &ERRORLEVEL=3}
               next-prompt
                  dept.
               undo, retry.
            end. /* IF NOT AVAILABLE dpt_mstr */

            pay_rate = emp_pay_rate.
            display
               dpt_desc @ dptdesc.

         end. /* IF INPUT emp <> "" */

         assign
            emp
            earn
            shift
            dept
            project.

         if available emp_mstr
         then
            display
               emp_lname.

         for first wc_mstr
            fields (wc_bdn_pct wc_bdn_rate wc_dept wc_lbr_rate wc_mch wc_wkctr)
            where wc_wkctr = input op_wkctr
            and   wc_mch   = input op_mch
            no-lock:
         end. /* FOR FIRST wc_mstr */

         if not available wc_mstr
            and input op_wkctr <> ""
         then do:
            next-prompt
               op_wkctr.

            /* WORK CENTER/MACHINE NOT FOUND */
            {pxmsg.i &MSGNUM=528 &ERRORLEVEL=3}
            undo, retry.
         end. /* IF NOT AVAILABLE wc_mstr ... */

         if available wc_mstr
         then
            display
               wc_wkctr @ op_wkctr
               wc_mch   @ op_mch.

         if     input emp      = ""
            and input op_wkctr = ""
         then do:

            next-prompt
               emp.

            /* BOTH EMPLOYEE AND WORK CENTER CANNOT BE LEFT BLANK */
            {pxmsg.i &MSGNUM=531 &ERRORLEVEL=3}
            undo, retry.
         end. /* if input emp = "" ... */

         if (input start_run <> "" or input stop_run <> "")
            or (input start_run <> input stop_run)
         then do:

            if input op_rsn = ""
               and can-find (first rsn_ref where rsn_type = "DOWN")
            then do:

               /* PLEASE ENTER REASON CODE */
               {pxmsg.i &MSGNUM=534 &ERRORLEVEL=1}

               prompt-for
                  op_rsn
               editing:

                  /* FIND NEXT/PREVIOUS RECORD */
                  {mfnp01.i rsn_ref op_rsn rsn_code "input op_type"
                     rsn_type rsn_type}

                  if recno <> ?
                  then
                     display
                        rsn_code @ op_rsn
                        rsn_desc @ rsn_desc1.

               end. /* IF recno <> ? */
            end. /* IF INPUT op_rsn ... */
         end. /* IF (INPUT start_run <> "") ... */

         if input op_rsn <> ""
         then do:

            for first rsn_ref
               fields (rsn_code rsn_desc rsn_type)
               where rsn_code = input op_rsn
               and   rsn_type = "DOWN"
               no-lock:
            end. /* FOR FIRST rsn_ref */

            if available rsn_ref
            then
               display
                  rsn_desc @ rsn_desc1.

            else do:

               display
                  "" @ rsn_desc1.

               /* INVALID REASON CODE */
               {pxmsg.i &MSGNUM=655 &ERRORLEVEL=2}
            end. /* IF NOT AVAILABLE rsn_ref */

         end. /* IF INPUT op_rsn <> "" */

         assign
            time_ind
            start_run
            stop_run.

         {mftimec.i start_run stop_run}

         display
            elapse @ op_act_run.

         if not time_ind
         then
            display
               time_hm1 format "999:99:99" @ start_run
               time_hm2 format "999:99:99" @ stop_run.

         else
            display
               time_hd1 @ start_run
               time_hd2 @ stop_run.

         /*  DO NOT ALLOW ZERO ELAPSED TIME    */
         if elapse = 0
         then do:

            next-prompt
               stop_run.

            /* ELAPSED DOWN TIME CANNOT BE ZERO  */
            {pxmsg.i &MSGNUM=1340 &ERRORLEVEL=3}
            undo, retry.
         end. /* IF elapse = 0 */

         for first gl_ctrl
            fields (gl_bdn_acct gl_bdn_cc gl_bdn_sub
                    gl_cop_acct gl_cop_cc gl_cop_sub
                    gl_lbr_acct gl_lbr_cc gl_lbr_sub gl_rnd_mthd)
            no-lock:
         end. /* FOR FIRST gl_ctrl */

         if not available gl_ctrl
         then do:

            msg_var1 = gledger.
            /* Please create # control */
            {pxmsg.i &MSGNUM=533 &ERRORLEVEL=3  &MSGARG1=msg_var1}
            undo, retry.
         end. /* IF NOT AVAILABLE gl_ctrl */

         assign
            sf_lbr_acct = gl_lbr_acct
            sf_lbr_sub  = gl_lbr_sub
            sf_lbr_cc   = gl_lbr_cc
            sf_bdn_acct = gl_bdn_acct
            sf_bdn_sub  = gl_bdn_sub
            sf_bdn_cc   = gl_bdn_cc
            sf_cop_acct = gl_cop_acct
            sf_cop_sub  = gl_cop_sub
            sf_cop_cc   = gl_cop_cc.

         yn = yes.

         /* IS ALL INFORMATION CORRECT */
         {pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn}

         if yn = no
            or input op_act_run = 0
         then
            undo, retry.

         global_site = input site.

         create op_hist.

         {mfnoptr.i}

         assign
            op_emp       = emp
            op_earn      = earn
            op_dept      = dept
            op_shift     = shift
            op_site      = si_site
            op_project   = project
            op_tran_date = today
            op_type      = "DOWN"
            op_wkctr
            op_mch
            op__chr01    = input op_rsn
            op_date      = eff_date
            op_act_run
            op_comment
            op_recno     = recid(op_hist).

         {sfnplgl.i}

      end. /* SET op_hist ... */
   end. /* DO TRANSACTION */
end. /* REPEAT */
